package com.cqjtu.eecs.utils.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ConverterUtils;
import com.alibaba.excel.util.ListUtils;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * @description: 无对象的excel读入监听器
 * @author: 徐文升
 * @create: 2022-03-11 09:52
 **/

@Data
public class NoModelDataListener implements ReadListener<Map<Integer, String>> {

    private List<Map<Integer, String>> dataList = ListUtils.newArrayList();
    private Map<Integer, String> headMap;

    @Override
    public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
        this.headMap = ConverterUtils.convertToStringMap(headMap, context);
    }

    @Override
    public void invoke(Map<Integer, String> data, AnalysisContext analysisContext) {
        if (data.get(0) != null)
            dataList.add(data);
    }


    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
